package com.hanrui.android.activity.message;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hanrui.android.R;
import com.hanrui.android.activity.message.receipt.ReceiptDocCheckActivity;
import com.hanrui.android.adapter.ReceiptDocListAdapter;
import com.hanrui.android.library.base.ActionBarBaseActivity;
import com.hanrui.android.model.ReceiptDocListBean;
import com.hanrui.android.net.contract.message.receipt.ReceiptDocListContract;
import com.hanrui.android.net.presenter.message.receipt.ReceiptDocListPresenter;
import com.hanrui.android.widget.SearchEditText;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 收文列表
 */
public class ReceiptDocListActivity extends ActionBarBaseActivity<ReceiptDocListPresenter> implements ReceiptDocListContract.View {

    @BindView(R.id.searchEditText)
    SearchEditText searchEditText;
    @BindView(R.id.recyclerview)
    RecyclerView mRecyclerView;

    @Inject
    ReceiptDocListAdapter adapter;


    @Override
    protected void initInjector() {mActivityComponent.inject(this); }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myperformance);

        unbinder = ButterKnife.bind(this);


        mTitleBar.setTitle("收文列表");

        setIsPullRefresh(true);
        setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                mPresenter.receiptDocList(ReceiptDocListActivity.this);


            }
        });


        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(adapter);
        adapter.setEmptyView(getNoDataView(mRecyclerView));
        adapter.setEnableLoadMore(false);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                ReceiptDocListBean.ReceiptDocListsBean bean = (ReceiptDocListBean.ReceiptDocListsBean) adapter.getItem(position);
                ReceiptDocCheckActivity.start(ReceiptDocListActivity.this,bean.getId(),bean.getProcInsId(),"");

            }
        });


        searchEditText.setEnabled(false);
//        searchEditText.setOnSearchClickListener(new SearchEditText.OnSearchClickListener() {
//            @Override
//            public void onSearchClick(View view, String keyword) {
//
//                mPresenter.performanceManagementList(ReceiptDocListActivity.this,name);
//            }
//        });


    }


    @Override
    protected void onResume() {
        super.onResume();
        setRefreshing();
        mPresenter.receiptDocList(this);
    }

    @Override
    public void receiptDocList(List<ReceiptDocListBean.ReceiptDocListsBean> dataList, int loadType) {

        setLoadDataResult(adapter,dataList,loadType,false);
    }
}
